#include "GUIButton.h"

GUIButton::GUIButton()
{
}

GUIButton::~GUIButton()
{	
}

void GUIButton::Initialize(std::string pText, sf::Vector2f pPos, sf::Font pFont)
{
	m_xDisplayManager = DisplayManager::GetInstance();
	m_xInput = InputHandler::GetInstance();

	m_xFont = pFont;

	m_vSize = sf::Vector2f(160.0f, 40.0f);
	m_vPos = pPos;

	m_cNormalColor = sf::Color::White;
	m_cHoverColor = sf::Color::Red;

	m_xShape = new sf::RectangleShape();
	m_xShape->setSize(m_vSize);
	m_xShape->setFillColor(sf::Color::White);
	m_xShape->setOutlineThickness(0);
	m_xShape->setPosition(m_vPos);
	m_xDisplayManager->AddDrawable(m_xShape, 9);

	m_tText = new sf::Text();
	m_tText->setFont(m_xFont);
	m_tText->setCharacterSize(30);
	m_tText->setColor(sf::Color::Black);
	m_tText->setPosition(sf::Vector2f(m_vPos.x + 10.0f, m_vPos.y));
	m_tText->setString(pText);
	m_tText->setStyle(sf::Text::Bold);
	m_xDisplayManager->AddDrawable(m_tText, 10);
}

void GUIButton::Update()
{
	if (MouseOver(m_xInput->GetMousePosition()))
	{
		SetBoxColor(m_cHoverColor);
	}
	else
	{
		SetBoxColor(m_cNormalColor);
	}
}

void GUIButton::Cleanup()
{
	m_xDisplayManager->DeleteDrawable(m_xShape);
	m_xDisplayManager->DeleteDrawable(m_tText);
}

bool GUIButton::MouseOver(sf::Vector2i pMousePos)
{
	if((pMousePos.x < m_vPos.x + m_xShape->getSize().x) && (pMousePos.x > m_vPos.x))
	{
		if((pMousePos.y < m_vPos.y + m_xShape->getSize().y) && (pMousePos.y > m_vPos.y))
		{
			return true;
		}
	}
	return false;
}

bool GUIButton::IsPressed(sf::Vector2i pMousePos)
{
	if(MouseOver(pMousePos) && m_xInput->isMouseDownFirst(sf::Mouse::Left))
	{
		return true;
	}
	return false;
}

void GUIButton::SetTextColor(sf::Color pColor)
{
	m_tText->setColor(pColor);
}

void GUIButton::SetBoxColor(sf::Color pColor)
{
	m_xShape->setFillColor(pColor);
}

void GUIButton::SetOutlineColor(sf::Color pColor)
{
	m_xShape->setOutlineColor(pColor);
}

//std::string GUIButton::GetName()
//{
//	return m_sName;
//}

sf::Color GUIButton::GetNormColor()
{
	return m_cNormalColor;
}

sf::Color GUIButton::GetHoveColor()
{
	return m_cHoverColor;
}